Imports System.Windows.Forms
Imports Vintasoft.Imaging
Imports Vintasoft.Pdf
Imports Vintasoft.Pdf.Tree
Imports DemosCommonCode.Pdf

Namespace Pdf
	Public Partial Class SelectResourceForm
		Inherits Form

		#Region "Fields"

		Private _resource As PdfImageResource
		Private _document As PdfDocument

		#End Region



		#Region "Constructors"

		Public Sub New(document As PdfDocument)
			InitializeComponent()
			_document = document
			exisingResourceButton.Enabled = _document.Images.Count > 0
		End Sub

		#End Region



		#Region "Properties"

		Public ReadOnly Property Resource() As PdfImageResource
			Get
				Return _resource
			End Get
		End Property

		#End Region



		#Region "Methods"

		Private Sub buttonCancel_Click(sender As Object, e As EventArgs)
			DialogResult = DialogResult.Cancel
		End Sub

		Private Sub exisingResourceButton_Click(sender As Object, e As EventArgs)
			Dim resourcesViewerDialog As New ResourcesViewerForm(_document.Images)
			If resourcesViewerDialog.ShowDialog() = DialogResult.OK Then
				_resource = TryCast(resourcesViewerDialog.SelectedResource, PdfImageResource)
				If _resource IsNot Nothing Then
					DialogResult = DialogResult.OK
				End If
			End If
		End Sub

		Private Sub newResourceButton_Click(sender As Object, e As EventArgs)
			If openImageFileDialog.ShowDialog() = DialogResult.OK Then
				Dim compressionParams As New ImageResourceCompressionParamsForm()
				If compressionParams.ShowDialog() = DialogResult.OK Then
					Using image As New VintasoftImage(openImageFileDialog.FileName)
						_resource = New PdfImageResource(_document, image, compressionParams.Compression, compressionParams.CompressionSettings)
					End Using
					DialogResult = DialogResult.OK
				End If
			End If
		End Sub

		#End Region

	End Class
End Namespace
